<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        /*
            统计数组中元素出现的次数
            [1,2,3,1,1,1,2,2,3,3,4]
                1出现的次数 4
                2出现的次数 3
                3出现的次数 3
                4出现的次数 1
         */

         var arr = [1,2,3,1,1,1,2,2,3,3,4]
         var res = arr.reduce(function(pre,cur){
             if( cur in pre){
                pre[cur] +=1
             }else{
                 pre[cur] = 1
             }
             return pre
         },{})
         console.log(res)
         for(var key in res){
             console.log(key + '出现了' + res[key] +'次')
         }
    </script>
</body>
</html>